package com.atguigu.bigdata.spark.core.rdd.operator.transform;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

import java.util.Arrays;
import java.util.List;

public class Spark07_RDD_Operator_Transform_JAVA {
    public static void main(String[] args) {
        //filter算子
        SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("sparkCore");
        JavaSparkContext sc = new JavaSparkContext(conf);

        List<Integer> list = Arrays.asList(1,2,3,4);
        JavaRDD<Integer>  rdd = sc.parallelize(list,2);
        JavaRDD<Integer> filterRdd =  rdd.filter(new Function<Integer, Boolean>() {
            @Override
            public Boolean call(Integer integer) throws Exception {
                return integer % 2 == 0;
            }
        });

        List<Integer> res = filterRdd.collect();
        for(Integer val : res) {
            System.out.println(val);
        }

        sc.stop();
    }
}
